package com.note.app.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.note.common.domain.AIConversation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * AI对话历史数据访问层
 */
@Mapper
public interface AIConversationMapper extends BaseMapper<AIConversation> {
    
    /**
     * 分页查询用户AI对话历史
     * 
     * @param page 分页参数
     * @param userId 用户ID
     * @return 分页结果
     */
    @Select("SELECT * FROM ai_conversation WHERE user_id = #{userId} AND deleted = 0 ORDER BY created_at DESC")
    IPage<AIConversation> selectPageByUserId(Page<AIConversation> page, @Param("userId") Long userId);
    
    /**
     * 查询用户最近的AI对话历史
     * 
     * @param userId 用户ID
     * @param limit 限制数量
     * @return AI对话历史列表
     */
    @Select("SELECT * FROM ai_conversation WHERE user_id = #{userId} AND deleted = 0 ORDER BY created_at DESC LIMIT #{limit}")
    List<AIConversation> selectRecentByUserId(@Param("userId") Long userId, @Param("limit") Integer limit);
    
    /**
     * 根据笔记ID查询关联的AI对话历史
     * 
     * @param noteId 笔记ID
     * @return AI对话历史列表
     */
    @Select("SELECT * FROM ai_conversation WHERE note_id = #{noteId} AND deleted = 0 ORDER BY created_at DESC")
    List<AIConversation> selectByNoteId(@Param("noteId") Long noteId);
} 